import React from "react";
import dayjs from "dayjs";

import type { DataAction, IProTableRef } from "@yaf/pro-ui";
import { getOperLogPageList, deleteOperLog } from "../../api";

export const getDataAction = (_: React.MutableRefObject<IProTableRef>): DataAction => ({
  fetchList: (params) => {
    const { page, pageSize, filter } = params;
    if(filter.dateRange){
      const [startTime, endTime] = filter.dateRange as dayjs.Dayjs[];
      filter.dateRange = JSON.stringify([startTime.format("YYYY-MM-DD"), endTime.format("YYYY-MM-DD")])
    }
    return getOperLogPageList(Object.assign({ page, pageSize }, filter || {})).then((resp) => resp.data);
  },
  deleteItems: (selectedRowKeys) => {
    return deleteOperLog(selectedRowKeys.map((item) => parseInt(item)))
  },
})


